import pymysql
from django.test import TestCase

# Create your tests here.
def conndb_and_exesql(sql):
    db = pymysql.connect(user='root', password='123456', db='baihuidb', host='127.0.0.1', port=3306,charset='utf8mb4')
    cursor = db.cursor()
    # sql1 = 'SELECT count(id) from apitest_apis where apistatus=1'
    cursor.execute('SELECT * FROM apitest_apis WHERE id=1')
    # 获取查询结果，返回元组
    result = cursor.fetchone()
    print(result)
    # for row in result:
    #     print(row)

    # 关闭游标和连接
    cursor.close()
    db.close()
    return result

if __name__ == '__main__':
    s = 'SELECT * FROM apitest_apis WHERE id=1'
    print(conndb_and_exesql(s))